﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace T5tk1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            // SqlDataReader reader = null;
            bool result = false;
            string sex = "";

            string id = UsName.Text.ToString().Trim();
            string pwd = UsPwd.Text.ToString().Trim();
            if (MAN.Checked)
            {
                sex = MAN.Text;
            }
            else if(WOMEN.Checked)
            {
                sex = WOMEN.Text;
            }
            else
            {
                MessageBox.Show("请选择性别");
            }
            if (id == "" || pwd == "")
            {
                MessageBox.Show("用户名或密码不能为空！", "非空提示");
            }
            string sql = string.Format("select * from admin2 where UserName='{0}'", id);
            SqlDataReader dr = DBHelper.GetDataReader(sql);
            while (dr.Read())
            {
                MessageBox.Show("该用户已存在！！！请换一个用户名");
                result = true;
                break;
            }
            dr.Close();

            if (result != true)
            {
                sql = string.Format("insert into admin2 (UserName,UserPwd,Sex) values('{0}','{1}','{2}')", id, pwd,sex);

                bool reader = DBHelper.ExecuteNonQuery(sql);
                MessageBox.Show("成功！");
            }

            /*DialogResult result = MessageBox.Show("是否继续注册", "提示",MessageBoxButtons.YesNo);
            if (result==DialogResult.No)
            {

            }
            else
            {
                
            }*/
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
